package cn.wolfcode.wms.service.impl;

import cn.wolfcode.wms.domain.ProductStock;
import cn.wolfcode.wms.mapper.ProductStockMapper;
import cn.wolfcode.wms.query.ProductStockQueryObject;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IProductStockService;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductStockServiceImpl implements IProductStockService{

    @Autowired
    private ProductStockMapper brandMapper;

    public void saveOrUpdate(ProductStock entity) {

        //判断是保存还是添加操作
        if (entity.getId() == null) {
            brandMapper.insert(entity);
        }else{
            brandMapper.updateByPrimaryKey(entity);
        }

    }

    public PageResult queryResult(ProductStockQueryObject qo) {
        Integer rows = brandMapper.queryForCount(qo);
        //判断数据库中的记录数是否为null
        if (rows==0) {
            return PageResult.EMPRY_PAGE;
        }
        //===============
        //如果数据库中有数据
        List<Map<String, Object>> data = brandMapper.queryForPage(qo);

        return new PageResult(data,rows,qo.getCurrentPage(),qo.getPageSize());
    }
}
